package com.twoGroup.boot.controller;

import com.twoGroup.boot.pojo.LikeAndGoods;
import com.twoGroup.boot.service.LikeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/Like")
@Api(tags = "用户喜欢接口")
public class LikeController {
    public static Logger logger = LoggerFactory.getLogger(LikeController.class);;

    @Autowired
    private LikeService likeService;

    //添加到用户喜欢
    @ApiOperation(value = "添加到用户喜欢", notes = "传入用户id ，goodsId,shopId 如果用户喜欢已存在或添加失败返回0 添加成功返回1")
    @PostMapping("/addUserLike")
    @ResponseBody
    public Integer addUserLike(Integer userId, Integer goodsId, Integer shopId){
        return likeService.addUserLike(userId,goodsId,shopId);
    }

    //删除喜欢
    @ApiOperation(value = "删除某个喜欢的商品", notes = "传入likeId  删除失败返回0 删除成功返回1")
    @PostMapping("/deleteLike")
    @ResponseBody
    public Integer deleteLike(Integer likeId){
        return likeService.deleteLike(likeId);
    }

    //删除所有喜欢
    @ApiOperation(value = "删除所有用户喜欢", notes = "传入用户id  删除失败返回0 删除成功返回1")
    @PostMapping("/deleteAllLike")
    @ResponseBody
    public Integer deleteAllLike(Integer userId){
        return likeService.deleteAllLike(userId);
    }

    @ApiOperation(value = "查询用户喜欢", notes = "传入用户id 返回list集合")
    @PostMapping("/selectAllLike")
    @ResponseBody
    public List<LikeAndGoods> selectAllLike(Integer userId){
        List<LikeAndGoods> list = likeService.selectAllLike(userId);
        for (LikeAndGoods likeAndGoods : list) {
            logger.info(String.valueOf(likeAndGoods));
        }
        return list;
    }

    @ApiOperation(value = "用户喜欢数量", notes = "传入用户id  返回数量 没有就返回0")
    @PostMapping("/selectCount")
    @ResponseBody
    public Integer selectCount(Integer userId){
        return likeService.selectCount(userId);
    }

}
